package com.example.gcmtest1.httpserver;

import java.io.FileOutputStream;

import android.content.Context;
import android.util.Log;

public class MyFileWriter {

	private String logName = "MyFileWriter";
	private String fileName;
	private Context context;
	private FileOutputStream fo = null;
	private String fullFileName = "";
	
	public MyFileWriter(Context context, String fileName) {
		this.context = context;
		
		Log.d(logName, "absPath=" + this.context.getFilesDir().getAbsolutePath());
		Log.d(logName, "fileStreamPath=" + this.context.getFileStreamPath(fileName));
		
		this.fullFileName = this.context.getFileStreamPath(fileName).toString();
		Log.d(logName, "fullFileName=" + this.fullFileName);
				
		try {
			this.fo = new FileOutputStream(this.context.getFileStreamPath(fileName), false);	
		} catch (Exception e) {
			Log.e(logName, "Cannot create FileOutputStream for '" + this.fullFileName + "'");
		}
				
	}
	
	public void append(byte[] b, int offset, int length) {
		try {
			if (this.fo != null) {
				this.fo.write(b, offset, length);
			}	
		} catch (Exception e) {
			Log.e(logName, "Error append file: '" + this.fullFileName + "' " + e.toString());
		}
		
	}
	
	public void closeFile() {
		if (this.fo != null) {
			
		} else {
			Log.d(logName, "cannot close file '" + this.fullFileName + "'");
		}
	}
	
	
	
	
}
